<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>商品销售退货管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../css/public.css" media="all">
	</head>
	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">
				<fieldset class="layui-elem-field layuimini-search">
					<legend>搜索信息</legend>
					<div style="margin: 10px 10px 10px 10px">
						<form class="layui-form layui-form-pane" action="" id="searchFrm">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">客户名称</label>
									<div class="layui-input-inline">
										<select name="customerid" class="customerSelect">
											<option value="">请选择客户</option>
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">商品名称</label>
									<div class="layui-input-inline">
										<select name="goodsid" class="goodsSelect">
											<option value="">请选择商品名称</option>
										</select>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">开始日期</label>
									<div class="layui-input-inline">
										<input type="text" name="startDate" id="startDate" autocomplete="off" class="layui-input" placeholder="请选择开始日期">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">结束时间</label>
									<div class="layui-input-inline">
										<input type="text" name="endDate" id="endDate" autocomplete="off" class="layui-input" placeholder="请选择结束日期">
									</div>
								</div>
								<div class="layui-inline">
									<div class="layui-block" style="text-align: center;">
										<a class="layui-btn" lay-submit="" lay-filter="data-search-btn">
											<i class="layui-icon layui-icon-search"></i>搜索</a>
										<a class="layui-btn layui-btn-warm" lay-submit="" lay-filter="data-reset-btn">
											<i class="layui-icon layui-icon-refresh"></i>重置</a>
									</div>
								</div>
							</div>

					</div>
					</form>
			</div>
			</fieldset>
			<!--表格开始-->
			<table class="layui-hide" id="salesbackTable" lay-filter="salesbackFilter"></table>
			<!--表格结束-->




		</div>
		</div>

		<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
		<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
		<script src="../../../lib/common/common.js" charset="utf-8"></script>

		<script>
			layui.use(['form', 'table', 'layer', 'laydate'], function() {
				var $ = layui.jquery,
					form = layui.form,
					table = layui.table,
					laydate = layui.laydate,
					layer = layui.layer; // 弹出层


				// 渲染时间选择器		
				laydate.render({
					elem: '#startDate', //指定元素
					type: 'datetime'
				});
				laydate.render({
					elem: '#endDate', //指定元素
					type: 'datetime'
				});

				/**
				 * 加载查询条件里面的客户下拉列表
				 */
				$.get(api + "customer/getAllAvailableCustomer", function(res) {
					var customerid = $(".customerSelect");
					var data = res.data;
					var html = "<option value = ''> 请选择客户 </option>";
					$.each(data, function(index, item) {
						html += "<option value = " + item.id + ">" + item.customername + "</option>";
					});
					customerid.html(html);
					form.render("select");
				})

				/**
				 * 加载查询条件里面的商品下拉列表
				 */
				$.get(api + "goods/getAllAvailableGoods", function(res) {
					var goodsid = $(".goodsSelect");
					var data = res.data;
					var html = "<option value = ''> 请选择商品名称 </option>";
					$.each(data, function(index, item) {
						html += "<option value = " + item.id + ">" + item.goodsname + "【" + item.size + "】" + " </option>";
					});
					goodsid.html(html);
					form.render("select");
				})

				// 加载 数据
				var tableIns = table.render({
					elem: '#salesbackTable',
					url: api + 'salesback/loadAllSalesback',
					title: '菜单数据表',
					toolbar: '#salesbackToolBar',
					height: 'full-220',

					cols: [
						[{
								field: 'customername',
								title: '客户名称',
								align: "center",
								width: 120
							},
							{
								field: 'goodsname',
								title: '商品名称',
								align: "center",
								width: 120
							},
							{
								field: 'number',
								title: '退货数量',
								align: "center",
								width: 100
							},
							{
								field: 'size',
								title: '规格',
								align: "center",
								width: 90
							},
							{
								field: 'salebackprice',
								title: '退货价格',
								align: "center",
								width: 100
							},
							{
								field: 'operateperson',
								title: '操作员',
								align: "center",
								width: 100
							},
							{
								field: 'paytype',
								title: '支付类型',
								align: "center",
								width: 110
							},
							{
								field: 'salesbacktime',
								title: '销售退货时间',
								align: "center",
								sort: true,
								width: 160
							},
							{
								field: 'operateperson',
								title: '操作员',
								align: "center",
								width: 120
							},
							{
								field: 'remark',
								title: '备注',
								align: "center"
							}
						]
					],
					done: function(data, curr, count) {
						//不是第一页时，如果当前返回的数据为0那么就返回上一页
						if (data.data.length === 0 && curr !== 1) {
							tableIns.reload({
								page: {
									curr: curr - 1
								}
							})
						}
					},
					// limits: [10, 15, 20, 25, 50, 100],
					// limit: 10,
					page: true
				});

				// 监听搜索操作
				form.on('submit(data-search-btn)', function(data) {
					var params = $("#searchFrm").serialize();
					//执行搜索重载
					table.reload('salesbackTable', {
						page: {
							curr: 1
						},
						url: api + 'salesback/loadAllSalesback?' + params
					});
					return false;
				});

				// 监听重置操作
				form.on('submit(data-reset-btn)', function(data) {
					$("#searchFrm")[0].reset(); // 清空搜索信息框中的数据
					//执行搜索重载
					table.reload('salesbackTable', {
						page: {
							curr: 1
						},
						url: api + 'salesback/loadAllSalesback'
					});
					return false;
				});

			});
		</script>
		<script>

		</script>

	</body>
</html>
